﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Zen4SyncDashboard.Converter
{
    [ValueConversion(typeof(DateTime), typeof(String))]
    public class DateTimeToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Can be null if the value comes from a DateTime? that has no value.
            if (value == null)
                return String.Empty;

            DateTime date;
            DateTime.TryParse(value.ToString(), out date);

            return date != DateTime.MinValue
                ? date.ToLocalTime().ToString()
                : String.Empty;            
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
